package com.mc.read.adminapi.service;

import com.alibaba.fastjson.JSON;
import com.mc.read.adminapi.Aspect.UserLog;
import com.mc.read.adminapi.manager.AdvertisingManager;
import com.mc.read.common.emun.ServiceCodeEnum;
import com.mc.read.common.exception.ServiceException;
import com.mc.read.vo.request.BaseRequest;
import com.mc.read.vo.respose.BaseRespose;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liuhao
 * @date 2019/6/26 15:33
 */
@Service
@Slf4j
public class AdvertisingService {

    @Autowired
    AdvertisingManager advertisingManager;

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询广告列表 selectAdverList
     **/
    @UserLog(operateName = "查询广告列表", type = 4)
    public BaseRespose selectAdverList(BaseRequest baseRequest) {
        log.info("查询广告列表,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = advertisingManager.selectAdverList(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("查询广告列表 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询广告列表 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 修改广告信息 updateAdver
     **/
    @UserLog(operateName = "updateAdver", type = 3)
    public BaseRespose updateAdver(BaseRequest baseRequest) {
        log.info("修改广告信息,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = advertisingManager.updateAdver(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("修改广告信息 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改广告信息 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询热点品论 selectHot
     **/
    @UserLog(operateName = "selectHot", type = 4)
    public BaseRespose selectHot(BaseRequest baseRequest) {
        log.info("查询热点品论,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = advertisingManager.selectHot(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("查询热点品论 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询热点品论 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 修改热门品论 updateHot
     **/
    @UserLog(operateName = "updateHot", type = 3)
    public BaseRespose updateHot(BaseRequest baseRequest) {
        log.info("修改热门品论,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = advertisingManager.updateHot(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("修改热门品论 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改热门品论 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

}
